<template>
  <el-dialog
    :close-on-click-modal="false"
    :title="`绑定${title}`"
    :visible.sync="visible"
    :before-close="close"
    lock-scroll
    append-to-body
  >
    <el-transfer
      :titles="transferTitle"
      v-model="value"
      :props="showProp"
      :data="data"
    ></el-transfer>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button :type="'primary'" :loading="loading" @click.native="save()"
        >保存</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
import { Message } from "element-ui";

export default {
  name: "BindRole",
  props: {
    visible: Boolean,
    baseStyle: Object,
    title: String,
    transferTitle: {
      type: Array,
      default: function () {
        return ["列表1", "列表2"];
      },
    },
    data: {
      type: Array,
      default: function () {
        return [];
      },
    },
    bindValue: {
      type: Array,
      default: function () {
        return [];
      },
    },
    showProp: {
      type: Object,
      default: function () {
        return {};
      },
    },
    saveForm: Function,
  },
  data() {
    return {
      loading: false,
      value: this.bindValue || [],
    };
  },
  computed: {},
  created() {},
  methods: {
    cancel() {
      this.value = [];
      this.loading = false;
      this.$emit("update:visible", false);
    },
    close() {
      this.cancel();
    },
    save() {
      if (this.value.length > 0) {
        this.loading = true;
        this.$emit("saveForm", [...this.value]);
      } else {
        this.$message.warning(`请选择${this.title}`);
      }
    },
  },
};
</script>
<style lang="scss" scoped>
</style>